package com.zretc.support.dao;

import com.zretc.support.entity.Course;
import com.zretc.support.entity.Joincourse;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.List;

@Repository
public interface CourseDao extends JpaRepository<Course,Long>, JpaSpecificationExecutor<Course>,
        CrudRepository<Course,Long>, Serializable {

    @Query("select c from Course c where  c.courseName like %?1%")
    Page<Course> getCourseByPage(String keywords, Pageable pageable);

    @Query("select c from Course c where  c.user.userName like %?1%")
    Page<Course> getCourseByPageByTea(String keywords, Pageable pageable);

    @Query("select c from Course c where c.user.userId = ?1 and c.courseName like %?2%")
    Page<Course> getCourseByTeacher(String userId, String keywords, Pageable pageable);

    @Query("select c from Course c,Joincourse j where c.courseId = j.course.courseId and j.user.userId = ?1 and c.courseName like %?2%")
    Page<Course> getCourseByStudent(String userId, String keywords, Pageable pageable);

    List<Course> getCourseByCourseNameContaining(String courseName);

    @Query("select c from Course c where c.user.userId=?1")
    List<Course> getAllCourseByTea(String userId);


}
